<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        const str = 'hello123,你好' ; 
        // encodeURIComponent 对一些特殊字符进行编码 --- 中文及特殊符号进行编码
        console.log(encodeURIComponent(str));


        const str2 = 'hello123%2C%E4%BD%A0%E5%A5%BD' ;
        // decodeURIComponent 对字符串进行解码
        console.log(decodeURIComponent(str2));



        const str3 = 'https://baike.baidu.com/item/%E5%90%8C%E6%BA%90%E7%AD%96%E7%95%A5/3927875?fr=aladdin' ;

        console.log(decodeURIComponent(str3));


        const uname = '小花' ;
        const upwd = '千锋' ;
        // 少部分浏览数存中文会乱码
        // 建议存储的时候，先进行编码
        localStorage.setItem(encodeURIComponent(uname) , encodeURIComponent(upwd)) ;   // 存的是编码格式的

        // console.log(localStorage.getItem(encodeURIComponent(uname)));   // 取的时候也必须使用编码来取

        let res = localStorage.getItem(encodeURIComponent(uname)) ;

        res = decodeURIComponent(res) ;

        console.log(res);

    </script>
    
</body>
</html>